﻿$.TableToJson=function(tableid) {
    var txt = "[";
    var table = document.getElementById(tableid);
    var row = table.getElementsByTagName("tr");
    var col = $("#"+tableid+" thead tr th");
    for (var j = 1; j < row.length; j++) {
        var r = "{";
        for (var i = 0; i < col.length; i++) {
            var tds = row[j].getElementsByTagName("td");
            r += "\"" + col.eq(i).attr("fieldname") + "\"\:\"" + $.trim(tds[i].innerHTML) + "\",";
        }
        r = r.substring(0, r.length - 1)
        r += "},";
        txt += r;
    }
    txt = txt.substring(0, txt.length - 1);
    txt += "]";
    return txt;
}

Date.prototype.Format = function (formatStr) {
    var str = formatStr;
    var Week = ['日', '一', '二', '三', '四', '五', '六'];
    var shijian = new Date();
    str = str.replace(/yyyy|YYYY/, shijian.getFullYear());
    str = str.replace(/yy|YY/, (shijian.getYear() % 100) > 9 ? (shijian.getYear() % 100).toString() : '0' + (shijian.getYear() % 100));

    str = str.replace(/MM/, shijian.getMonth() > 9 ? shijian.getMonth().toString() : '0' + (shijian.getMonth()+1).toString());
    str = str.replace(/M/g, shijian.getMonth());

    str = str.replace(/w|W/g, Week[shijian.getDay()]);

    str = str.replace(/dd|DD/, shijian.getDate() > 9 ? shijian.getDate().toString() : '0' + shijian.getDate());
    str = str.replace(/d|D/g, shijian.getDate());

    str = str.replace(/hh|HH/, shijian.getHours() > 9 ? shijian.getHours().toString() : '0' + shijian.getHours());
    str = str.replace(/h|H/g, shijian.getHours());
    str = str.replace(/mm/, shijian.getMinutes() > 9 ? shijian.getMinutes().toString() : '0' + shijian.getMinutes());
    str = str.replace(/m/g, shijian.getMinutes());

    str = str.replace(/ss|SS/, shijian.getSeconds() > 9 ? shijian.getSeconds().toString() : '0' + shijian.getSeconds());
    str = str.replace(/s|S/g, shijian.getSeconds());

    return str;
}